<!--
  用户管理-学生用户-学生用户列表
 -->
<template>
  <div class="app-container">
    <!-- 搜索工作栏 -->
    <el-form
      ref="queryForm"
      :model="queryParams"
      size="small"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="手机号" prop="mobile">
        <el-input
          v-model="queryParams.mobile"
          placeholder="请输入手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="认证状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="请选择学生状态"
          clearable
          size="small"
        >
          <el-option label="已认证" value="1" />
          <el-option label="未认证" value="2" />
        </el-select>
      </el-form-item>
      <el-form-item label="姓名" prop="studentName">
        <el-input
          v-model="queryParams.studentName"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        <el-button
          type="primary"
          icon="el-icon-search"
          @click="handleQuery"
        >搜索</el-button>
      </el-form-item>
    </el-form>
    <!-- 操作工具栏 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="16">
        <el-button
          v-if="isSuperAdmin"
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="exportDate()"
        >导出学生信息（当前条件）</el-button>
        <!-- <el-button
          v-if="isSuperAdmin"
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="exportDateAll()"
        >导出学生信息（全部）</el-button> -->
        <el-button
          v-if="isSuperAdmin"
          type="primary"
          icon="el-icon-upload2"
          size="mini"
          @click="mutipleImport"
        >批量导入学生</el-button>
        <el-button
          v-if="isSuperAdmin"
          type="primary"
          icon="el-icon-upload2"
          size="mini"
          @click="importSingleStuden"
        >导入单个学生</el-button>
      </el-col>
    </el-row>
    <!-- 列表 -->
    <el-table v-loading="loading" :data="list" @sort-change="sortChange">
      <el-table-column label="序号" type="index" />
      <el-table-column label="用户名" align="center" prop="nickname" />
      <el-table-column label="认证状态" align="center" prop="status">
        <template slot-scope="scope">
          <span>
            {{ studenStatus[scope.row.status] || "--" }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="国籍" align="center" prop="studentAbroad">
        <template slot-scope="scope">
          <span>{{
            scope.row.studentAbroad === 1 ? "中国内地学生" : "非中国内地学生"
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="籍贯" align="center" prop="nativePlace" />
      <el-table-column label="手机号" align="center" prop="mobile" />
      <el-table-column label="邮箱" align="center" prop="email" />
      <el-table-column
        sortable="custom"
        label="创建时间"
        align="center"
        prop="createTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        sortable="custom"
        label="最近登录"
        align="center"
        prop="loginDate"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.loginDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleCheck(scope.row)"
          >个人信息</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="checkRecordList(scope.row)"
          >投递情况</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleEdit(scope.row)"
          >编辑账号</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      :page-sizes="[10, 20, 30, 50, 100]"
      @pagination="getList"
    />
    <!-- 编辑学生个人信息 -->
    <el-dialog
      :title="dialogTitle"
      :visible.sync="openUserForm"
      width="50%"
      append-to-body
    >
      <el-form
        ref="userForm"
        :model="userForm"
        :rules="rules"
        label-width="80px"
      >
        <el-form-item label="头像" prop="studentPictureUrl">
          <img
            v-if="isCheck"
            v-imgError
            style="display: block; width: 146px"
            :src="userForm.studentPictureUrl"
            alt="头像"
          >
          <imageUpload v-else v-model="userForm.studentPictureUrl" />
        </el-form-item>
        <el-form-item label="姓名" prop="nickname">
          <el-input
            v-model="userForm.nickname"
            :disabled="isCheck"
            placeholder="请输入姓名"
          />
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          <el-select v-model="userForm.sex" :disabled="isCheck">
            <el-option value="男" label="男">男</el-option>
            <el-option value="女" label="女">女</el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="出生日期" prop="birthday">
          <el-date-picker
            v-model="userForm.birthday"
            :disabled="isCheck"
            type="date"
            value-format="yyyy-MM-dd hh:mm:ss"
            placeholder="选择日期"
          />
        </el-form-item> -->
        <el-form-item label="民族" prop="clan">
          <el-select v-model="userForm.clan" :disabled="isCheck">
            <el-option
              v-for="item in nationData"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="政治面貌" prop="political">
          <el-input
            v-model="userForm.political"
            :disabled="isCheck"
            placeholder="请输入政治面貌"
          />
        </el-form-item>
        <el-form-item label="居住城市" prop="liveCity">
          <el-input
            v-model="userForm.liveCity"
            :disabled="isCheck"
            placeholder="请输入城市"
          />
        </el-form-item>
        <el-form-item label="籍贯" prop="nativePlace">
          <el-input
            v-model="userForm.nativePlace"
            :disabled="isCheck"
            placeholder="请输入籍贯"
          />
        </el-form-item>
        <el-form-item label="联系方式" prop="mobile">
          <el-input
            v-model="userForm.mobile"
            disabled
            placeholder="请输入联系方式"
          />
        </el-form-item>
        <el-form-item label="邮箱地址" prop="email">
          <el-input
            v-model="userForm.email"
            :disabled="isCheck"
            placeholder="请输入邮箱地址"
          />
        </el-form-item>
      </el-form>
      <el-row type="flex" class="row-bg" justify="end">
        <el-button
          v-if="isCheck"
          type="primary"
          @click="isCheck = false"
        >编辑</el-button>
        <el-button
          v-if="!isCheck"
          type="primary"
          @click="modefyUserForm"
        >提交</el-button>
        <el-button
          type="primary"
          @click="handleCheckResume"
        >查看简历</el-button>
        <el-button @click="cancel">取 消</el-button>
      </el-row>
    </el-dialog>
    <!-- 编辑学生账户信息(头像、姓名、手机号) -->
    <el-dialog
      title="编辑账户信息"
      :visible.sync="openAccountForm"
      width="500px"
      append-to-body
    >
      <el-form
        ref="accountFrom"
        :model="accountFrom"
        :rules="rules"
        label-width="80px"
      >
        <el-form-item label="头像" prop="studentPictureUrl">
          <imageUpload v-model="accountFrom.studentPictureUrl" />
        </el-form-item>
        <el-form-item label="姓名" prop="nickname">
          <el-input v-model="accountFrom.nickname" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="手机号" prop="mobile">
          <el-input v-model="accountFrom.mobile" placeholder="请输入手机号" />
        </el-form-item>
      </el-form>
      <el-row type="flex" class="row-bg" justify="end">
        <el-button type="primary" @click="modefyAccountForm">提交</el-button>
        <el-button @click="cancel">取 消</el-button>
      </el-row>
    </el-dialog>
    <!-- 投递情况 -->
    <el-drawer
      title="投递情况"
      :visible.sync="recordDialog"
      :direction="direction"
      size="80%"
    >
      <el-tabs v-model="activeName" type="card">
        <el-tab-pane label="应聘" name="hire">
          <HireCom :id="studentId" ref="HireCom" />
        </el-tab-pane>
        <!-- <el-tab-pane disabled label="项目" name="subject"> 2 </el-tab-pane>
        <el-tab-pane disabled label="课程" name="course"> 3 </el-tab-pane> -->
      </el-tabs>
    </el-drawer>
    <el-drawer
      title="简历"
      :visible.sync="resumeDialog"
      :direction="direction"
      size="60%"
    >
      <ResumeReview ref="ResumeReview" :is-data-list="true" />
    </el-drawer>
    <!-- 批量导入学生 -->
    <el-dialog
      :title="upload.title"
      :visible.sync="upload.open"
      width="400px"
      append-to-body
    >
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :on-error="handleFileError"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload" />
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div slot="tip" class="el-upload__tip text-center">
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link
            type="primary"
            :underline="false"
            style="font-size: 12px; vertical-align: baseline"
            @click="importTemplate"
          >下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="handleFileError">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog
      title="导入单个学生"
      :visible.sync="isOpenSingleImport"
      width="50%"
      append-to-body
    >
      <el-form
        ref="singleStudentForm"
        :model="singleStudentForm"
        :rules="rules"
        label-width="100px"
      >
        <el-form-item label="姓名" prop="studentName">
          <el-input
            v-model="singleStudentForm.studentName"
            placeholder="请输入姓名"
          />
        </el-form-item>
        <el-form-item label="手机号" prop="mobile">
          <el-input
            v-model="singleStudentForm.mobile"
            placeholder="请输入手机号"
          />
        </el-form-item>
        <el-form-item label="学生类型" prop="studentAbroad">
          <el-select
            v-model="singleStudentForm.studentAbroad"
            placeholder="请选择学生类型"
            @change="clearCardNoAndPassport"
          >
            <el-option label="国内" value="国内" />
            <el-option label="非中国内地学生" value="国外" />
          </el-select>
        </el-form-item>
        <el-form-item
          v-if="singleStudentForm.studentAbroad === '国内'"
          label="身份证号"
          prop="cardNo"
        >
          <el-input
            v-model="singleStudentForm.cardNo"
            placeholder="请输入身份证号"
          />
        </el-form-item>
        <el-form-item
          v-if="singleStudentForm.studentAbroad === '国外'"
          label="护照号"
          prop="passport"
        >
          <el-input
            v-model="singleStudentForm.passport"
            placeholder="请输入护照号"
          />
        </el-form-item>
        <el-form-item label="民族" prop="clan">
          <el-select v-model="singleStudentForm.clan">
            <el-option
              v-for="item in nationData"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          <el-select v-model="singleStudentForm.sex" placeholder="请选择">
            <el-option label="男" value="男" />
            <el-option label="女" value="女" />
          </el-select>
        </el-form-item>
        <el-form-item label="出生日期" prop="stuBirthday">
          <el-date-picker
            v-model="singleStudentForm.stuBirthday"
            :picker-options="pickTime"
            type="date"
            size="large"
            placeholder="选择出生日期"
            value-format="yyyy-MM-dd"
            format="yyyy-MM-dd"
          />
        </el-form-item>
        <el-form-item label="居住城市" prop="liveCity">
          <el-cascader
            v-model="singleStudentForm.liveCity"
            :options="provinceAndCityData"
            :show-all-levels="false"
          />
        </el-form-item>
        <el-form-item label="籍贯" prop="nativePlace">
          <el-cascader
            v-model="singleStudentForm.nativePlace"
            :options="provinceAndCityData"
            :show-all-levels="false"
          />
        </el-form-item>
        </el-form-item>
        <el-form-item label="简历名称" prop="name">
          <el-input
            v-model="singleStudentForm.name"
            placeholder="请输入简历名称(默认模版一)"
          />
        </el-form-item>
        <el-form-item label="大学名称" prop="schoolName">
          <el-input
            v-model="singleStudentForm.schoolName"
            placeholder="请输入大学名称"
          />
        </el-form-item>
        <el-form-item label="教育状态" prop="educationalBackground">
          <el-select
            v-model="singleStudentForm.educationalBackground"
            placeholder="请选择教育状态"
          >
            <el-option label="大专" value="大专" />
            <el-option label="本科" value="本科" />
            <el-option label="硕士" value="硕士" />
            <el-option label="博士" value="博士" />
          </el-select>
        </el-form-item>
        <el-form-item label="政治面貌" prop="political">
          <el-select
            v-model="singleStudentForm.political"
            placeholder="请输入政治面貌"
          >
            <el-option label="团员" value="团员" />
            <el-option label="中共党员(含预备党员)" value="中共党员(含预备党员)" />
            <el-option label="民主党派" value="民主党派" />
            <el-option label="无党派人士" value="无党派人士" />
            <el-option label="群众" value="群众" />
          </el-select>
        </el-form-item>
        <el-form-item label="是否有学位证书" prop="diploma">
          <el-select
            v-model="singleStudentForm.diploma"
            placeholder="是否有学位证书"
          >
            <el-option label="是" value="是" />
            <el-option label="否" value="否" />
          </el-select>
        </el-form-item>
        <el-form-item label="所学专业" prop="major">
          <el-input v-model="singleStudentForm.major" placeholder="所学专业" />
        </el-form-item>
        <el-form-item label="是否全日制" prop="fullTime">
          <el-select
            v-model="singleStudentForm.fullTime"
            placeholder="是否全日制"
          >
            <el-option label="是" value="是" />
            <el-option label="否" value="否" />
          </el-select>
        </el-form-item>
        <el-form-item label="当前身份" prop="identify">
          <el-select
            v-model="singleStudentForm.identify"
            placeholder="是否有学位证书"
          >
            <el-option label="在校" value="在校" />
            <el-option label="应届" value="应届" />
          </el-select>
        </el-form-item>
        <el-form-item label="是否有海外留学经历" prop="isOverseasStudy">
          <el-select
            v-model="singleStudentForm.isOverseasStudy"
            placeholder="是否有海外留学经历"
          >
            <el-option label="有" value="有" />
            <el-option label="无" value="无" />
          </el-select>
        </el-form-item>
        <el-form-item label="当前状态" prop="jobStatus">
          <el-select
            v-model="singleStudentForm.jobStatus"
            placeholder="当前状态"
          >
            <el-option label="正在实习" value="正在实习" />
            <el-option label="暂无实习" value="暂无实习" />
          </el-select>
        </el-form-item>
        <el-form-item label="入职时间" prop="inJobTime">
          <el-select
            v-model="singleStudentForm.inJobTime"
            placeholder="入职时间"
          >
            <el-option label="随时入职" value="随时入职" />
            <el-option label="2周内入职" value="2周内入职" />
            <el-option label="一个月内入职" value="一个月内入职" />
          </el-select>
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input
            v-model="singleStudentForm.email"
            placeholder="请输入邮箱"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button
          type="primary"
          @click="submitSingleStudentForm"
        >提交</el-button>
        <el-button @click="cancelSingleStudent">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  getStudentPage,
  deleteStudent,
  updateStudent,
  getStudentInfo,
  getStudentResume
} from '@/api/school-admin-api/userManage/student/index.js'
import ImageUpload from '@/components/ImageUpload'
import { getNationData, provinceAndCityData, businessAreaData, getProvinceAndCityDataLabel } from '@/utils/frontDataDict.js'
import { deepClone } from '@/utils/index'
import HireCom from './components/hire.vue'
import moment from 'moment'
import ResumeReview from '@/components/resumeReview/index.vue'
import { mapGetters } from 'vuex'
import { insertSingleStudentAccount } from '@/api/company-admin-api/userManage/index.js'
import { exportStudentInfo } from '@/api/company-admin-api/hireManage/index.js'
import { getBaseHeader } from '@/utils/request'

export default {
  name: 'Company',
  components: {
    ImageUpload,
    HireCom,
    ResumeReview
  },
  data() {
    const validatePhone = (rule, value, callback) => {
      const phoneReg = /^[1][0-9]{10}$/
      if (value === '') {
        return callback(new Error('手机号不能为空'))
      } else {
        if (phoneReg.test(value)) {
          return callback()
        } else {
          return callback(new Error('格式有误'))
        }
      }
    }
    const validataEmail = (rule, value, callback) => {
      const emailReg =
        /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/
      if (value === '') {
        return callback(new Error('请输入邮箱'))
      } else {
        if (emailReg.test(value)) {
          return callback()
        } else {
          return callback(new Error('格式有误'))
        }
      }
    }
    return {
      provinceAndCityData,
      studentId: '',
      nationData: getNationData(),
      dialogTitle: '',
      activeName: 'hire',
      direction: 'rtl',
      recordDialog: false, // 投递情况列表
      isCheck: true, // 查看
      openAccountForm: false,
      // 企业行业类型数据，二级联动
      businessAreaData: businessAreaData,
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 企业管理列表
      list: [],
      pickTime: {
        disabledDate: (time) => {
          return time.getTime() > Date.now() - 8.64e6
        }
      },
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        studentName: null,
        mobile: null,
        status: null,
        sortingFields: {
          field: '',
          order: ''
        }
      },
      // 个人信息弹窗
      accountFrom: {
        applyUserName: '', // 姓名
        dept: '', // 头像
        phoneNumber: '' // 手机号
      },
      // 用户信息表
      userForm: {
        nickname: '', // 学生姓名
        sex: '', // 性别
        birthday: '', // 出生日期，毫秒值
        clan: '', // 民族
        political: '', // 政治面貌
        liveCity: '', // 居住城市
        graduateTime: '', // 毕业时间
        nativePlace: '', // 籍贯
        studentPictureUrl: '', // 学生证件照
        mobile: '', // 手机号
        email: '' // 邮箱
      },
      // 表单校验
      rules: {
        studentName: [
          { required: true, message: '请输入姓名', trigger: 'blur' }
        ],
        stuBirthday: [
          { required: true, message: '清选择出生日期', trigger: 'change' }
        ],
        studentAbroad: [
          { required: true, message: '请选择学生类型', trigger: 'change' }
        ],
        cardNo: [
          { required: true, message: '请输入身份证号', trigger: 'blur' }
        ],
        major: [
          { required: true, message: '请输入所学专业', trigger: 'blur' }
        ],
        passport: [
          { required: true, message: '请输入护照号', trigger: 'blur' }
        ],
        jobStatus: [
          { required: true, message: '请选择当前状态', trigger: 'change' }
        ],
        inJobTime: [
          { required: true, message: '请选择入职时间', trigger: 'change' }
        ],
        isOverseasStudy: [
          { required: true, message: '请选择是否有海外留学经历', trigger: 'change' }
        ],
        fullTime: [
          { required: true, message: '请选择是否全日制', trigger: 'change' }
        ],
        liveCity: [
          { required: true, message: '请选择居住城市', trigger: 'change' }
        ],
        educationalBackground: [
          { required: true, message: '请选择教育状态', trigger: 'change' }
        ],
        diploma: [
          { required: true, message: '请选择是否有学位证书', trigger: 'change' }
        ],
        identify: [
          { required: true, message: '请选择当前身份', trigger: 'change' }
        ],
        political: [
          { required: true, message: '请选择政治面貌', trigger: 'change' }
        ],
        nativePlace: [
          { required: true, message: '请选择籍贯', trigger: 'change' }
        ],
        schoolName: [
          { required: true, message: '请输入学校名称', trigger: 'change' }
        ],
        name: [
          { required: true, message: '请输入简历名称（默认模版一）', trigger: 'change' }
        ],
        nickname: [
          {
            required: true,
            message: '姓名不能为空',
            trigger: 'blur'
          }
        ],
        mobile: [{ required: true, validator: validatePhone, trigger: 'blur' }],
        email: [{ required: true, validator: validataEmail, trigger: 'blur' }],
        clan: [
          {
            required: true,
            message: '选择民族',
            trigger: 'change'
          }
        ],
        sex: [
          {
            required: true,
            message: '选择性别',
            trigger: 'change'
          }
        ]
      },
      resumeDialog: false,
      openUserForm: false, // 查看/编辑 弹窗
      currentRow: null, // 当前操作行,
      userInfo: null,
      // studentAuthStatus 0 默认状态， 1 认证通过， 2 认证驳回 3 认证中
      studenStatus: {
        0: '未认证',
        1: '已认证',
        2: '驳回',
        3: '认证中'
      },
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: '',
        // 是否禁用上传
        isUploading: false,
        // 设置上传的请求头部
        headers: getBaseHeader(),
        // 上传的地址
        url:
          process.env.VUE_APP_BASE_API +
          'admin-api/member/student/import-excel'
      },
      isOpenSingleImport: false,
      singleStudentForm: {
        cardNo: '', // 身份证号
        clan: '', // 民族
        diploma: '', // 是否有学位证书
        educationalBackground: '', // 教育状态
        email: '', // 邮箱
        fullTime: '', // 是否全日制
        identify: '', // 当前身份
        inJobTime: '', // 入职时间
        isOverseasStudy: '', // 是否有海外留学经历
        jobStatus: '', // 当前状态
        liveCity: '', // 居住城市
        major: '', // 所学专业
        mobile: '', // 手机号码
        name: '模版一', // 简历名称
        nativePlace: '', // 籍贯
        passport: '', // 护照号
        political: '', // 政治面貌
        schoolName: '', // 大学名称
        sex: '', // 性别
        stuBirthday: '', // 出生日期
        studentAbroad: '国内', // 学生类型
        studentName: '' // 学生姓名
      },
      isOpenStudentsExportDialog: false
    }
  },
  computed: {
    ...mapGetters(['roles']),
    isSuperAdmin() {
      return (
        Array.isArray(this.roles) && this.roles.indexOf('super_admin') > -1
      )
    }
  },
  created() {
    this.getList()
  },
  methods: {
    clearCardNoAndPassport(e) {
      console.log('111', e, this.$refs)
      this.$refs.singleStudentForm && this.$refs.singleStudentForm.clearValidate(['cardNo', 'passport'])
    },
    // 打开单个学生导入弹窗
    importSingleStuden() {
      this.isOpenSingleImport = true
    },
    // 单个学生表单校验
    submitSingleStudentForm() {
      this.$refs.singleStudentForm.validate((boo) => {
        if (boo) {
          const params = JSON.parse(JSON.stringify(this.singleStudentForm))
          params.liveCity = getProvinceAndCityDataLabel(params.liveCity)
          params.nativePlace = getProvinceAndCityDataLabel(params.nativePlace)
          insertSingleStudentAccount(params).then(res => {
            if (res && res.code === 0) {
              this.$message.success('创建成功')
              this.cancelSingleStudent()
              this.getList()
            }
          })
        }
      })
    },
    cancelSingleStudent() {
      this.$refs.singleStudentForm &&
        this.$refs.singleStudentForm.resetFields()
      setTimeout(() => {
        this.isOpenSingleImport = false
      }, 20)
    },
    importTemplate() {
      window.open(
        'https://demo-oss.oss-cn-beijing.aliyuncs.com/批量导入学生信息模版-202312190120307858.xlsx',
        '_blank'
      )
    },
    exportDate() {
      const params = JSON.parse(JSON.stringify(this.queryParams))
      // status 1 认证 2 未认证
      // 0 默认状态， 1 认证通过， 2 认证驳回 3 认证中
      if (Number(params.status) === 1) {
        params.status = [1]
      } else if (Number(params.status) === 2) {
        params.status = [0, 2, 3]
      }
      for (const key in params) {
        if (params[key] === null || params[key] === '') {
          delete params[key]
        }
      }
      if (params.sortingFields.order === '') {
        delete params.sortingFields
      } else {
        params.sortingFields = [params.sortingFields]
      }
      exportStudentInfo(params).then((response) => {
        this.$download.excel(response, '学生信息.xls')
      })
    },
    exportDateAll() {
      this.isOpenStudentsExportDialog = true
    //   const params = {
    //     pageNo: 1,
    //     pageSize: 99999999
    //   }
    //   exportStudentInfo(params).then((response) => {
    //     this.$download.excel(response, '学生信息.xls')
    //   })
    },
    mutipleImport() {
      this.upload.title = '批量导入学生'
      this.upload.open = true
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit()
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      if (response.code !== 0) {
        this.$modal.msgError(response.msg)
        return
      }
      this.$refs.upload.clearFiles()
      this.upload.open = false
      this.upload.isUploading = false
      // 拼接提示语
      const data = response.data
      this.$alert(data, '导入结果', { dangerouslyUseHTMLString: true })
      this.handleQuery()
    },
    // 上传报错，清除文件并关闭
    handleFileError() {
      this.$refs.upload.clearFiles()
      this.upload.open = false
      this.upload.isUploading = false
    },
    // 查看简历
    handleCheckResume() {
      const id = this.currentRow.id
      getStudentResume({ studentId: id }).then((res) => {
        if (
          res.code === 0 &&
          res.data &&
          res.data.studentCurriculumVitaeRespVOList.length > 0
        ) {
          this.resumeDialog = true
          setTimeout(() => {
            this.$refs.ResumeReview.open(
              res.data.studentCurriculumVitaeRespVOList,
              this.userInfo
            )
          })
        }
      })
    },
    // 编辑学生个人中心信息
    modefyUserForm() {
      this.$refs.userForm.validate((boo) => {
        if (boo) {
          const userForm = deepClone(this.userForm)
          userForm.birthday = moment(userForm.birthday).valueOf()
          userForm.graduateTime = moment(userForm.graduateTime).valueOf()
          updateStudent(userForm).then((res) => {
            if (res.code === 0 && res.data) {
              this.$message.success('更新成功')
              this.openUserForm = false
              this.getList()
            }
          })
        }
      })
    },
    // 修改账号信息
    modefyAccountForm() {
      updateStudent(this.accountFrom).then((res) => {
        if (res.code === 0 && res.data) {
          this.$message.success('更新成功')
          this.openAccountForm = false
          this.getList()
        }
      })
    },
    sortChange({ column, prop, order }) {
      console.log('排序变化>>>', column, prop, order)
      const sortType = {
        ascending: 'asc',
        descending: 'desc'
      }
      const sortingFields = {
        field: prop,
        order: order !== null ? sortType[order] : null
      }
      if (order === null) {
        Object.assign(this.queryParams.sortingFields, {
          field: '',
          order: ''
        })
        this.getList()
      } else {
        Object.assign(this.queryParams.sortingFields, sortingFields)
        this.getList()
      }
    },
    /** 查询列表 */
    getList() {
      this.loading = true
      // 处理查询参数
      const params = deepClone(this.queryParams)
      // status 1 认证 2 未认证
      // 0 默认状态， 1 认证通过， 2 认证驳回 3 认证中
      if (Number(params.status) === 1) {
        params.status = [1]
      } else if (Number(params.status) === 2) {
        params.status = [0, 2, 3]
      }
      for (const key in params) {
        if (params[key] === null || params[key] === '') {
          delete params[key]
        }
      }
      if (params.sortingFields.order === '') {
        delete params.sortingFields
      } else {
        params.sortingFields = [params.sortingFields]
      }
      // 执行查询
      getStudentPage(params).then((response) => {
        this.list = response.data.list
        this.total = response.data.total
        this.loading = false
      })
    },
    /** 取消按钮 */
    cancel() {
      this.openAccountForm = false
      this.openUserForm = false
      this.reset()
    },
    /** 表单重置 */
    reset() {
      this.form = this.$options.data().form
      this.userForm = this.$options.data().userForm
      this.companyForm = this.$options.data().companyForm
      this.resetForm('form')
      this.resetForm('userForm')
      this.resetForm('companyForm')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 编辑学生账户信息 ,打开弹窗
    handleEdit(row) {
      this.isCheck = false
      this.dialogTitle = '编辑个人信息'
      const { id } = row
      getStudentInfo({ id }).then((res) => {
        if (res.code === 0 && res.data) {
          this.accountFrom = deepClone(res.data)
          this.openAccountForm = true
        }
      })
    },
    // 查看学生个人信息
    handleCheck(row) {
      this.isCheck = true
      this.currentRow = JSON.parse(JSON.stringify(row))
      this.dialogTitle = '查看个人信息'
      const { id } = row
      getStudentInfo({ id }).then((res) => {
        if (res.code === 0 && res.data) {
          this.userInfo = res.data
          if (res.data.birthday) {
            res.data.birthday = moment(res.data.birthday).format(
              'yyyy-MM-DD HH:mm:ss'
            )
          }
          if (res.data.graduateTime) {
            res.data.graduateTime = moment(res.data.graduateTime).format(
              'yyyy-MM-DD HH:mm:ss'
            )
          }
          this.userForm = deepClone(res.data)
          this.openUserForm = true
        }
      })
    },
    /** 修改按钮操作 */
    checkRecordList(row) {
      this.studentId = row.id
      this.recordDialog = true
      setTimeout(() => {
        this.$refs.HireCom.getList()
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const nickname = row.nickname
      this.$confirm('是否确认删除学生' + nickname, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteStudent(row.id)
          .then((res) => {
            if (res.code === 0 && res.data) {
              this.$message.success('删除成功审核')
              this.getList()
            }
          })
          .catch(() => console.info('操作取消'))
      })
    }
  }
}
</script>
